// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var common = require("../../../css/common.css");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var css_detail_info = require("./applyMain.css");
	var html_valuation = require("./applyValuation.html");
	var tools = require("tools");
	var constant = require("constant");
	var str1 = '<div class="fuid" ><a class="financeEvidentiary" fileUuid="" target="_blank"><img class="short" src="../../../res/png/contract1.png" /></a><img style="cursor:pointer;" class="sub1" src="../../../res/png/sub_icon.png" /><span></span></div>';
	var fileElementId;
	var financeId;
	var productType;
	var enterpriseId;
	var oData
	var html;
	var bulkstockObj = {
		bulkstockId: [],
		bulkstockName: [],
		specificationName: [],
		bulkstockNumber: [],
		measurement: [],
		conversionFactor: []
	};	
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var init = function(page) {
		enterpriseId = page.params.enterpriseId;
		productType = page.params.productType;
		$("input[name='enterpriseId']").val(enterpriseId);
		$("input[name='productType']").val(productType);
		oData = {
			pageIndex: pageIndex,
			pageSize: pageSize,
			totalPageCount: totalPageCount,
			totalRecordCount: totalRecordCount
		};
		getCommodityCategory();
		getProvinceList();
		tools.inquireCommonSelectorByStringList(15, $("#apply_main select[name=enterpriseInsurer]"));
		tools.inquireCommonSelectorByStringList(16, $("#apply_main select[name=enterpriseInsuranceType]"));
		inquireCurrentEnterpriseDetail();
		router.init();
		initEvent();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		//改变货物类别
		$("#main").on("change", "#commodityCategory", function() {
			if ($(this).val() != "") {
				inquireBulkstockPageList($(this).val(), $(".commodityNames"));
				inquireBulkstockCategoryDetail($(this).val());
				$("#commodityCategoryHidden").val($("#commodityCategory  option:selected").text());
			} else {
				$(".bulkstockMaterial").addClass("none");
			}
		});
		
		//改变货物
		$("#main").on("change", ".commodityNames", function() {
			var commodityName = $(this).parent().find("option:selected").text();
			$(this).parent().find(".bulkstockNames").val(commodityName);
			$(this).parent().find(".measurement").val($(this).parent().find("option:selected").attr("measurement"));
			$(this).parent().find(".conversionFactor").val($(this).parent().find("option:selected").attr("conversionFactor"));
			existBulkstockPledgeRate($(this).val(), null, null);
		});
		
		$(".instructionsLink").on("mouseenter", function() {
			$(this).parent().find(".instructions").removeClass("none");
		});
		
		$(".instructionsLink").on("mouseleave", function() {
			$(this).parent().find(".instructions").addClass("none");
		});
		
		$("#main").on("click", ".valuationLink", function() {
			var measurement = $(this).parent().parent().find(".measurement").val();
			var volumes = $(this).parent().parent().find(".volumes").val();
			var weights = $(this).parent().parent().find(".weights").val();
			var conversionFactor = $(this).parent().parent().find(".conversionFactor").val();
			if ($(this).parents(".goods").find(".commodityNames").val() != "") {
				if (measurement == 0) {
					base.alert(2, "大宗商品单位计量类型不能为空！");
					return;
				} else if (measurement == 2) {
					if ($(this).parent().parent().find(".weights").val() == "") {
						base.alert(2, "此商品按重量计量，重量不能为空！");
						return;
					}
				} else {
					return;
				}
				pageIndex = 1;
				$("#popdialog").html(html_valuation);
				dialog.showDialog($("#applyValuation"));
				databind.fillInput($("#valuationContentDetail"), {
					action: "inquireBulkstockGatherLatestList.json?bulkstockInfoId=" + $(this).parents(".goods").find(".commodityNames").val(),
					nocode: true
				});
				var s = $(this).parents(".goods").find(".commodityNames").find("option:selected").text();
				$(".dialogTitle").html(s + "价格估值");
				var unit = "";
				var quantity = 0;
				if (measurement == 1) {
					unit = "体积：";
					quantity = volumes;
				} else if (measurement == 2) {
					unit = "重量：";
					quantity = weights;
				}
				$(".valuationInputUnit").html(unit);
				$(".valuationQuantity").val(quantity);
				inquireBulkstockLatestCollectionList($(this).parents(".goods").find(".commodityNames").val(), conversionFactor, $(this).parents(".goods").find("select[name=dataSourceId]").val());
				$("#valuationCancel").unbind("click").click(function() {
					dialog.hideDialog($("#applyValuation"));
				});
				var dom = $(this).parents(".goods");
				$("#valuationSure").unbind("click").click(function() {
					dom.find(".bulkstockValuation").val($("#valuationPrice").html());
					dom.find(".bulkstockPrice").val($(".valuationRegionPrice").val());
					changeBulkstockValuation();
					dialog.hideDialog($("#applyValuation"));
				});
				//手动改变片区价格
				$(".valuationRegionPrice").unbind("change").change(function() {
					var valuationRegionPrice = $(".valuationRegionPrice").val();
					var valuationQuantity = $(".valuationQuantity").val();
					$("#valuationPrice").html((valuationRegionPrice * valuationQuantity).toFixed(2));
				});

				//				$(".publicMonitor").unbind("click").click(function() {
				//					var bulkstockname = $(this).parents("tr").attr("bulkstockname");
				//					var specification = $(this).parents("tr").attr("specification");
				//					var latestgatherId = $(this).parents("tr").attr("latestgatherid");
				//					var region = $(this).parents("tr").attr("region");
				//					//						location.href="../publicInquire/publicInquireCollectionMonitor.html?bulkstockName="+encodeURI(encodeURI(bulkstockname))+"&specification="+encodeURI(encodeURI(specification))+"&region="+encodeURI(encodeURI(region))+"&latestgatherId="+latestgatherId;
				//					window.open("../publicInquire/publicInquireCollectionMonitor.html?bulkstockName=" + encodeURI(encodeURI(bulkstockname)) + "&specification=" + encodeURI(encodeURI(specification)) + "&region=" + encodeURI(encodeURI(region)) + "&latestgatherId=" + latestgatherId);
				//				});

				riseAndFallColor();
			} else {
				base.alert(2, "请选择货物！");
			}
		});
		
		tools.loadSelectList($("select[name=dataSourceId]"), "inquireDataSourceList.json", "dataSourceId", "dataSource");
		
		$("#main").on("change", "#receiveProvince", function() {
			var provinceId = $("#receiveProvince").val();
			getCityList(provinceId);
			$("#receiveCity").html(html);
			$(".receiveProvince").val($("#receiveProvince option:selected").text());
		});
		
		$("#main").on("change", "#receiveCity", function() {
			var cityId = $("#receiveCity").val();
			getDistrictList(cityId);
			$("#receiveDistrict").html(html);
			$(".receiveCity").val($("#receiveCity option:selected").text());
		});
		
		$("#main").on("change", "#receiveDistrict", function() {

			$(".receiveDistrict").val($("#receiveDistrict option:selected").text());
		});

		$("#main").on("change", "#deliverProvince", function() {
			var provinceId = $("#deliverProvince").val();
			getCityList(provinceId);
			$("#deliverCity").html(html);
			$(".deliverProvince").val($("#deliverProvince option:selected").text());
		});

		$("#main").on("change", "#deliverCity", function() {
			var cityId = $("#deliverCity").val();
			getDistrictList(cityId);
			$("#deliverDistrict").html(html);
			$(".deliverCity").val($("#deliverCity option:selected").text());
		});

		$("#main").on("change", "#deliverDistrict", function() {
			$(".deliverDistrict").val($("#deliverDistrict option:selected").text());
		});
		
		//拟借款金额变化
		$("#apply_main").on("change", "#applicationAmount", function() {
			var d = $("#applicationAmount").val();
			var v = $("#valuation").val();
			var cm = $(".data[name=creditLineRemains]").html();

			if (v == "") {
				base.alert(2, "请先对货物进行估值！");
				$("#applicationAmount").val("");
			} else {
				if (parseFloat(d) > parseFloat(v)) {
					base.alert(2, "借款金额不能大于货物估值！");
					$("#applicationAmount").val(v);
					return;
				}
				
				if ((d/10000)*1 > cm*1) {
					base.alert(2, "授信额度不足！");
					return;
				}
			}
		});
		
		$("#main").on("change", "#applicationAmount", function() {
			var v = $("#valuation").val();
			var a = $("#applicationAmount").val();
			if ($.trim(v) == "") {
				return;
			}
			
			$(".adv span").html((a * 100/v).toFixed(2));
			
			$.each($("select[name=bulkstockInfoIds]"), function(){
				if ($(this).val() == null || $(this).val() == "") {
					layer.msg("请先选择融资货物");
					return;
				}
				existBulkstockPledgeRate($(this).val(), $(".adv span").html(), null);
			});
		});
		
		$("#apply_main_next").click(function() {
			
			if ($(".freightListInfos").length > 0 && $(".freightListInfo2 tbody tr").length > 0) {
				var freightAmount = 0; //发票信息总价
				var settlementAmount = 0; //运单信息结算总价
				//若二者都不为空，校验发票金额和结算总价
				
				$.each($(".freightListInfos"), function(){
					var $this = $(this);
					if ($this.find("input[name=invoiceAmount]").val() != null && $this.find("input[name=invoiceAmount]").val() != "") {
						freightAmount = freightAmount*1 + $this.find("input[name=invoiceAmount]").val()*1;
					}
				});
				
				$.each($(".freightListInfo2 tbody tr"), function(){
					var $this = $(this);
					if ($this.find("input[name=settlementPrices]").val() != null && $this.find("input[name=settlementPrices]").val() != "") {
						settlementAmount = settlementAmount*1 + $this.find("input[name=settlementPrices]").val()*1;
					}
				});
				
				if (freightAmount != settlementAmount) {
					base.alert(2, "运单总额和发票总额不匹配！");
					return;	
				}
			}
			
			var cm = $(".data[name=creditLineRemains]").html();
			var d = $("#applicationAmount").val();
			
			if ((d/10000)*1 > cm*1) {
				base.alert(2, "授信额度不足！");
				return;
			}
			
			//对属性赋值
			financeId = $("#financeId").val();
			
			if (financeId.length != 0) {
				//$(".financeApplicationContent").attr("action", "updateFinanceApplication");
			} else {
				$(".financeApplicationContent").attr("action", "proxyCreateFinanceApplication");
			}

			var promptString = validate.isPhone($("#receiveContactPhone"));
			if (promptString.length > 0) {
				base.alert(2, "收货联系人电话" + promptString);
				return;
			}
			promptString = validate.isPhone($("#deliverContactPhone"));
			if (promptString.length > 0) {
				base.alert(2, "交货联系人电话" + promptString);
				return;
			}
			
			databind.submitDom($(".financeApplicationContent"), function(data) {
				if (financeId.length != 0) {
					base.alert(1, "代理申请融资成功");
					//router.route("apply/apply_upload_material.html?financeId=" + financeId + "&bulkstockCategoryId=" + commodityCategoryId + "&userID=" + userID + "&productType=" + productType, true);
				} else {
					base.alert(1, "代理申请融资成功");
					//router.route("apply/apply_upload_material.html?financeId=" + data.datas[0].financeId + "&bulkstockCategoryId=" + commodityCategoryId + "&userID=" + userID + "&productType=" + productType, true);
				}

			});

		});
		
		$("#main").on("change", ".approve input", function() {
			fileElementId = $(this).attr("id");
			uploadMaterial(fileElementId);
		});
		
	};
	
		//获取货物类别
	var getCommodityCategory = function() {
		base.fnAjax({
			action: "inquireBulkstockCategoryPageList.json",
			async: false,
			nocode: true,
			oData: {
				activeState: true,
				productType: productType
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#commodityCategoryTpl").html();
					var html = juicer(tpl, data);
					$("#commodityCategory").html(html);
					
					if (productType == 4) {
						
						$("input[name=enterpriseInsuranceNumber]").parents(".dataLine").remove();
						$("input[name=enterpriseForceAmount]").parents(".dataLine").remove();
						$("input[name=enterpriseInsuranceAmount]").parents(".dataLine").remove();
						$("input[name=declaredValue]").parents(".applyDataLine").remove();
						$(".goodsfrom .star").remove();
						$("#receiveProvince").attr("isNull", "0");
						$(".receiveProvince").attr("isNull", "0");
						$("#receiveCity").attr("isNull", "0");
						$(".receiveCity").attr("isNull", "0");
						$(".goodsto .star").remove();
						$("#deliverProvince").attr("isNull", "0");
						$(".deliverProvince").attr("isNull", "0");
						$("#deliverCity").attr("isNull", "0");
						$(".deliverCity").attr("isNull", "0");
						$("#deliverAddress").attr("isNull", "0");
						$("#receiveAddress").attr("isNull", "0");
						$("input[name=bookingSpaceNumber]").parents(".applyDataLine").remove();
//						$("input[name=enterpriseInsuranceNumber]").parents(".applyDataLine").remove();
						$("#addCaseInfo").remove();
						
						$("input[name=weights]").val(1);
						$("input[name=volumes]").val(1).parent().addClass("none");
						$(".valuationLink").attr("style", "visibility: hidden; margin-right: 100px;");
						$(".receiver").html("出质");
						$(".deliver").html("债务");
						
						$(".require_package").remove();
						$(".require_tag").remove();
						$(".require_storage").remove();
						$(".require_keep").remove();
						$(".label_info3").remove();
						$(".line:last").remove();
						
						$(".cargoMark").parent().remove();
						$("#coldStorage").parent().parent().remove();
//						$("#commodityCategory").attr("disabled", "disabled");
//						$("#commodityCategory option[txt='保理业务']").attr("selected", true);
//						$("#commodityCategoryHidden").val("保理业务");
						inquireBulkstockPageList($("#commodityCategory").val(), $(".commodityNames"));
						
						tools.loadList("inquireLogisticsCompanyAll.json", $("#deliverList"), $("#deliverList script"), null, function(){
						}, null);
						
						$("#commodityCategoryHidden").parent().parent().find(".bulkstockCategory").html("产品类别");
						$("#goods1 .label").remove();
						$(".goods_name .bulkstockName").html("产品名称");
						$(".manufacturers").parent().remove();
						$(".bulkstockValuationName").html("发票总价");
						$(".goodsto .select_label").html("出质方地址：");
						$(".goodsto").css("margin-left", "0");
						$(".goodsfrom .select_label").html("债务方地址：");
						$(".goodsfrom").css("margin-left", "0");
						
						$(".labeltitle").html("票据信息");
						$("#progress").attr("src", "../../../res/png/progress_apply11.png");
					} else {
						$(".freightListInfo").remove();
					}
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//获取省/州列表
	var getProvinceList = function() {
		base.fnAjax({
			action: "inquireZoneProvinceList.json",
			async: false,
			nocode: true,
			oData: {
				pageSize: 100
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#provinceTpl").html();
					html = juicer(tpl, data);
					$("#receiveProvince").html(html);
					$("#deliverProvince").html(html);
					$("#originPlaces").html(html);
					
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//大宗商品列表
	var inquireBulkstockPageList = function(bulkstockCategoryId, dom) {
		base.fnAjax({
			action: "inquireBulkstockPageList.json",
			async: false,
			nocode: true,
			oData: {
				bulkstockCategoryId: bulkstockCategoryId,
				pageSize: 100
			}, //传递参数
			fnSuccess: function(data) {
				bulkstockObj = {
					bulkstockId: [],
					bulkstockName: [],
					specificationName: [],
					bulkstockNumber: [],
					measurement: [],
					conversionFactor: []
				};
				if (data.status == 200) {
					for (var j = 0; j < data.datas.length; j++) {
						bulkstockObj.bulkstockName.push(data.datas[j].bulkstockName);
						bulkstockObj.bulkstockId.push(data.datas[j].bulkstockInfoId);
						bulkstockObj.bulkstockNumber.push(data.datas[j].bulkstockNumber);
						bulkstockObj.specificationName.push(data.datas[j].specificationName);
						bulkstockObj.measurement.push(data.datas[j].measurement);
						bulkstockObj.conversionFactor.push(data.datas[j].conversionFactor);
					}
					$(dom).children().remove();
					$(dom).append('<option value="">请选择货物名称</option>');
					for (var j = 0; j < bulkstockObj.bulkstockName.length; j++) {
						var str = '<option value="' + bulkstockObj.bulkstockId[j] + '" measurement="' + bulkstockObj.measurement[j] + '"  conversionFactor="' + bulkstockObj.conversionFactor[j] + '">' + bulkstockObj.bulkstockName[j] + '(' + bulkstockObj.specificationName[j] + ')' + '</option>';
						$(dom).append(str);
					}
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//获取货物类别详情
	var inquireBulkstockCategoryDetail = function(bulkstockCategoryId) {
		base.fnAjax({
			action: "inquireBulkstockCategoryDetail.json",
			async: true,
			nocode: true,
			oData: {
				bulkstockCategoryId: bulkstockCategoryId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var str = "";
					for (var j = 0; j < data.datas[0].templates.length; j++) {
						str += data.datas[0].templates[j].templateName + ",";
					}
					str = str.substring(0, str.length - 1);
					$("#bulkstockMaterial").html(str);
					$(".bulkstockMaterial").removeClass("none");
					$(".bulkstockMaterial").css("display", "block");
					
					var tpl = $("#approveTpl").html(); //证明资料
					var html = juicer(tpl, data);
					$("#approveBody").html(html);
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	var existBulkstockPledgeRate = function(bulkstockInfoId, pledgeRate, loanRate) {
		base.fnAjax({
			action: "existBulkstockPledgeRate.json",
			async: false,
			nocode: true,
			oData: {
				bulkstockInfoId: bulkstockInfoId,
				productType: productType,
				pledgeRate: pledgeRate,
				loanRate: loanRate,
				enterpriseId: enterpriseId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					if (!data.datas[0].isExist) {
						layer.msg("对不起，您暂无该货物的融资权限，请联系客服!");
					}
				} else {
					layer.msg(data.message);
				}
			}
		});
	};
	
	//最新商品采集价格列表
	var inquireBulkstockLatestCollectionList = function(bulkstockInfoId, conversionFactor, dataSourceId) {
		base.fnAjax({
			action: "inquireBulkstockLatestCollectionList.json",
			async: false,
			nocode: true,
			oData: {
				pageSize: pageSize,
				pageIndex: pageIndex,
				bulkstockInfoId: bulkstockInfoId,
				dataSourceId: dataSourceId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#bulkstockCollectionListTpl").html();
					var html = juicer(tpl, data);
					$("#bulkstockCollectionListBody").html(html);

					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($("#valuationPagenation"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							inquireBulkstockLatestCollectionList(bulkstockInfoId, conversionFactor);
						});

					$(".priceCheck").on("click", function() {
						var price = parseFloat($(this).parents("tr").find(".price").html()) * conversionFactor;
						$(".valuationRegionPrice").val(price.toFixed(6));
						var valuationRegionPrice = $(".valuationRegionPrice").val();
						var valuationQuantity = $(".valuationQuantity").val();
						if (valuationRegionPrice == "") {
							valuationRegionPrice = 0;
						}
						if (valuationQuantity == "") {
							valuationQuantity = 0;
						}
						$("#valuationPrice").html((valuationRegionPrice * valuationQuantity).toFixed(2));
					});
					//估值弹出框 --查看事件绑定
					$(".publicMonitor").unbind("click").click(function() {
						var bulkstockname = $(this).parents("tr").attr("bulkstockname");
						var specification = $(this).parents("tr").attr("specification");
						var latestgatherId = $(this).parents("tr").attr("latestgatherid");
						var region = $(this).parents("tr").attr("region");
						//						location.href="../publicInquire/publicInquireCollectionMonitor.html?bulkstockName="+encodeURI(encodeURI(bulkstockname))+"&specification="+encodeURI(encodeURI(specification))+"&region="+encodeURI(encodeURI(region))+"&latestgatherId="+latestgatherId;
						window.open("../publicInquire/publicInquireCollectionMonitor.html?bulkstockName=" + encodeURI(encodeURI(bulkstockname)) + "&specification=" + encodeURI(encodeURI(specification)) + "&region=" + encodeURI(encodeURI(region)) + "&latestgatherId=" + latestgatherId);
					});
				} else {
					base.alert(3, "信息获取失败");
				}
			}
		});
	};
	
	//改变涨跌颜色
	var riseAndFallColor = function() {
		var riseAndFall = $(".riseAndFall");
		for (var i = 0, j = riseAndFall.length; i < j; i++) {
			if (riseAndFall[i].innerHTML.charAt(0) == "-") {
				$(riseAndFall[i]).css("color", "#33A55E");
			} else if (riseAndFall[i].innerHTML.charAt(0) == "+") {
				$(riseAndFall[i]).css("color", "#F1592A");
			} else {
				$(riseAndFall[i]).css("color", "#F1592A");
			}
		}
	};
	
	//货物估值变动
	var changeBulkstockValuation = function() {
			var valuation = 0;
			$(".bulkstockValuation").each(function(i, val) {
				valuation += parseFloat($(this).val());
			});
			$("#valuation").val(valuation.toFixed(2));
			$("#chineseMoney").html(tools.changeMoneyToChinese(valuation.toFixed(2)));
	};
	
	//获取城市列表
	var getCityList = function(provinceId) {
		base.fnAjax({
			action: "inquireZoneCityList.json",
			async: false,
			nocode: true,
			oData: {
				provinceId: provinceId,
				pageSize: 100
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#cityTpl").html();
					html = juicer(tpl, data);
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};

	//获取区县
	var getDistrictList = function(cityId) {
		base.fnAjax({
			action: "inquireZoneDistrictList.json",
			async: false,
			nocode: true,
			oData: {
				cityId: cityId,
				pageSize: 100
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#districtTpl").html();
					html = juicer(tpl, data);
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//判断质押率和贷款率。
	/*var existBulkstockPledgeRate = function(bulkstockInfoId, pledgeRate, loanRate) {
		base.fnAjax({
			action: "existBulkstockPledgeRate.json",
			async: false,
			nocode: true,
			oData: {
				bulkstockInfoId: bulkstockInfoId,
				productType: productType,
				pledgeRate: pledgeRate,
				loanRate: loanRate
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					if (!data.datas[0].isExist) {
						layer.msg("对不起，您暂无该货物的融资权限，请联系客服!");
					}
				} else {
					layer.msg(data.message);
				}
			}
		});
	};*/
	
	var inquireCurrentEnterpriseDetail = function() {
		base.fnAjax({
			action: "inquireEnterpriseDetail.json",
			async: false,
			oData: {
				enterpriseId: enterpriseId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					databind.fillForm($(".creditLineDom"), data.datas[0].enterpriseGradeDetail);
					$(".data[name=creditLine]").html(($(".data[name=creditLine]").html()/10000).toFixed(2));
					$(".data[name=creditAlready]").html(($(".data[name=creditAlready]").html()/10000).toFixed(2));
					$(".data[name=creditLineRemains]").html(($(".data[name=creditLineRemains]").html()/10000).toFixed(2));
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
		//上传文件
	var uploadMaterial = function(fileElementId) {
		$.ajaxFileUpload({
			url: "/finance/api/v1.0/uploadFile.json", //你处理上传文件的服务端
			secureuri: false,
			fileElementId: fileElementId,
			dataType: 'json',
			async: true,
			success: function(data) {
				var dom = $(document.getElementById(fileElementId));
				dom.before(str1);
				dom.parent().find("a:last").attr({
					"href": "/finance/api/v1.0/downloadFile.file?fileUuid=" + data.data[0].fileUuid,
					"materialFileuuid": data.data[0].fileUuid,
					"templateName": dom.parents(".materiaData").attr("templateName"),
					"templateId": dom.parents(".materiaData").attr("templateId"),
					"evidentiaryCategoryId": 0,
					"evidentiaryId": 0
				});
				dom.parent().find("span:last").html(data.data[0].fileName);
				dom.parent().find(".sub1:last").click(function() {
					$(this).parent().remove();
				});
			},
			complete: function(xml) {},
			error: function(data, status, e) {
				if (data.msg == null) {
					base.alert(2, "文件太大无法上传");
				} else {
					base.alert(2, data.msg);
				}
			}
		});
	};
	
	return {
		init: init
	};
});

